#ifndef __RENDERERWIN32_H_API__
#define __RENDERERWIN32_H_API__
#include <map>

#include "Defines.h"
#include "VertexBufferWin32.h"
#include "Texture.h"


enum Matrix_Mode
{
	World = D3DTS_WORLDMATRIX(0),
	View = D3DTS_VIEW,
	Projection = D3DTS_PROJECTION
};

enum DrawPrimitives
{
	TRIANGLE_LIST = D3DPRIMITIVETYPE::D3DPT_TRIANGLELIST,
	TRIANGLE_FAN = D3DPRIMITIVETYPE::D3DPT_TRIANGLEFAN,
	LINE_LIST = D3DPRIMITIVETYPE::D3DPT_LINELIST,
	LINE_STRIP = D3DPRIMITIVETYPE::D3DPT_LINESTRIP,
	POINT_LIST = D3DPRIMITIVETYPE::D3DPT_POINTLIST,
	TRIANGLE_STRIP = D3DPRIMITIVETYPE::D3DPT_TRIANGLESTRIP
};

class ENGINE_API Renderer{
private:
	HWND* winHandle;
	IDirect3DDevice9* graphCardHandle; //LPDIRECT3D9 g_pDirect3D; + LPDIRECT3DDEVICE9 g_pDirect3D_Device; aparentemente
	Matrix_Mode matrixMode;
	D3DXVECTOR3 viewerPos;
	D3DXVECTOR3 viewerUp;

	D3DXMATRIX projectionMatrix;
	D3DXMATRIX viewerMatrix;

	VertexBuffer<COL_VERTEX, D3DFVF_XYZRHW|D3DFVF_DIFFUSE> * colVertexBuffer;
	VertexBuffer<TEX_VERTEX, D3DFVF_XYZ|D3DFVF_TEX1|D3DFVF_TEXCOORDSIZE2(0)> * texVertexBuffer;
	void *pVertexBuffer;

	void Translate(float x, float y, float z);
	void Scale(float x, float y);
	void RotateX(float angle);
	void RotateY(float angle);
	void RotateZ(float angle);
	/**/
protected:
	std::map<std::string, IDirect3DTexture9 *> textureMap;
	typedef std::map<std::string, IDirect3DTexture9 *>::iterator texIterator;
public:
	Renderer(HWND);
	~Renderer();

	void bindTexture(tex_ptr* tex);
	void unBindTexture();
	bool loadTexture(tex_ptr* texture);
	
	void Draw(COL_VERTEX* vertexCollection, unsigned int uiVertexCount, DrawPrimitives ePrim);
	void Draw(TEX_VERTEX* vertexCollection, unsigned int uiVertexCount, DrawPrimitives ePrim);

	void loadIdentity();
	void setMatrixMode(Matrix_Mode mode);
	void setViewportPosition();

	void StartFrame();
	void EndFrame();

	friend class Game; //
	friend class Entity2D;

};

#endif